package cn.shadow.consumer.config;

import cn.shadow.msg.TestMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.Message;

import java.util.function.Consumer;

/**
 * @author 冯啸迪
 */
@Configuration
public class ConsumerConfig {

    private static final Logger log = LoggerFactory
            .getLogger(ConsumerConfig.class);

    /**
     * 广播消费
     * @return
     */
    @Bean
    public Consumer<Message<TestMessage>> consumer() {
        return message -> {
            log.info(Thread.currentThread().getName() + " consumerBroadcast Receive New Messages: " + message.getPayload().getMsg());
        };
    }

    /**
     * 正常消费
     * @return
     */
    @Bean
    public Consumer<Message<TestMessage>> consumerTest() {
        return message -> {
            log.info(Thread.currentThread().getName() + " test Receive New Messages: " + message.getPayload().getMsg());
        };
    }

    @Bean
    public Consumer<Message<TestMessage>> consumerCluster() {
        return message -> {
            log.info(Thread.currentThread().getName() + " consumerCluster Receive New Messages: " + message.getPayload().getMsg());
        };
    }

}
